// pages/myOrder/myOrder.js
const app = getApp();
const typeList = ['全部','小程序', '腾讯云','定制'];

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pages: 0,
    barSelected: 0,
    status: 0,
    date: '',
    typeList: typeList,
    orderList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  // 获取列表
  getMyTencentCloudOrderList: function() {
    var that = this;
    this.data.pages++;
    var data = {
      point_url: app.server.agentApi.getMyTencentCloudOrderList,
      type: this.data.status,
      pageNumber: this.data.pages,
      pageSize: 10,
      start_time: this.data.date
    };
    app.server.getConnect(data).then(function(res) {
      that.setData({
        orderList: that.data.orderList.concat(res.data.rows||[])
      })

    })
  },

  // 菜单栏点击
  bindStatusChange: function() {
    var that = this;
    wx.showActionSheet({
      itemList: typeList,
      success(res) {
        that.setData({
          barSelected: 0,
          status: res.tapIndex,
          pages: 0,
          orderList: []
        });
        that.getMyTencentCloudOrderList();
      }
    })
  },

  bindDateChange(e) {
    this.setData({
      barSelected: 1,
      date: e.detail.value,
      pages: 0,
      orderList: []
    });
    this.getMyTencentCloudOrderList();
  },

  // 跳转订单详情
  toOrderDetails: function(e) {
    var details = JSON.stringify(e.currentTarget.dataset.details || '');
    wx.navigateTo({
      url: '/pages/agent/tencentCloud/orderDetails/orderDetails?details=' + details,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getMyTencentCloudOrderList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getMyTencentCloudOrderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
